package com.dream.inspect.modules.job.task;



import com.dream.inspect.modules.app.controller.common.CommonMethod;
import com.dream.inspect.modules.business.dao.SuperviseProjectDao;
import com.dream.inspect.modules.business.dao.SuperviseStandardDao;
import com.dream.inspect.modules.business.dao.SuperviseTargetDao;
import com.dream.inspect.modules.business.entity.SuperviseProjectEntity;
import com.dream.inspect.modules.business.entity.SuperviseTargetEntity;
import com.dream.inspect.modules.business.service.SysMessageService;
import com.dream.inspect.modules.sys.entity.SysUserEntity;
import com.dream.inspect.modules.sys.service.SysUserService;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Component("sendMessageTask")
public class SendMessageTask{
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private SuperviseStandardDao superviseStandardDao;
	@Autowired
	SysMessageService sysMessageService;
	@Autowired
	CommonMethod commonMethod;
	@Autowired
	SuperviseProjectDao superviseProjectDao;
	@Autowired
	SuperviseTargetDao superviseTargetDao;

	/**
	 * 新增问题整改截止前36小时系统提醒消息
	 * @param params 检查项Id ， 被检查单位部门Id
	 */
	public void sendQuestionEnd(String params){
		logger.info("开始新增问题整改截止前36小时系统消息");
		String[] arr = params.split(",");
		String deptId = arr[1];
		String questionName = superviseStandardDao.selectById(arr[0]).getQuestionDescription();
		String noticeTitle = "限时整改剩余36小时提醒！";
		String noticeContent = "您的单位问题" + questionName + "还未整改，限时剩余36小时，请关注！";
		Map<String, String> map = new HashMap<String, String>();
		map.put("noticeTitle", noticeTitle);
		map.put("noticeContent", noticeContent);
		map.put("userId", "1");//系统管理员
		map.put("deptId", deptId);//通知单位Id
		map.put("roles", ";1;");//角色为督察员
		sysMessageService.insertMessage(map);
		logger.info("结束新增问题整改截止前36小时系统消息");
	}

	/**
	 * 专项截止给申请专项单位发送提醒消息
	 * @param params 专项Id
	 */
	public void sendProjectEnd(String params){
		Map<String, String> paramsTemp = new HashMap<String, String>();
		SuperviseProjectEntity s = superviseProjectDao.selectById(params);
		if(s != null){
			String tNoticeTitle = "专项截止";
			String tContentText = "专项"+ s.getTitleName() + "已经截止";
			paramsTemp.put("noticeTitle", tNoticeTitle);
			paramsTemp.put("noticeContent", tContentText);
			String tRoles = commonMethod.getRolesByDeptId(s.getZbdwId()+""); //接收角色
			paramsTemp.put("roles", tRoles);
			paramsTemp.put("userId", "1");
			paramsTemp.put("deptId", s.getZbdwId()+"");
			sysMessageService.insertMessage(paramsTemp);
		}
	}

	/**
	 * 专项截止前36小时给未执行专项的单位发送提醒消息
	 * @param params 专项Id
	 */
	public void sendProjectEnd36(String params){
		Map<String, String> paramsTemp = new HashMap<String, String>();
		SuperviseProjectEntity s = superviseProjectDao.selectById(params);
		if(s != null){
			List<SuperviseTargetEntity> stList = superviseTargetDao.getNoExecuteProjectListById(params);
			String tNoticeTitle = "专项截止剩余36小时";
			String tContentText = "您的单位还未执行过专项"+ s.getTitleName() + "的督察任务，请尽快执行！";
			paramsTemp.put("noticeTitle", tNoticeTitle);
			paramsTemp.put("noticeContent", tContentText);
			for (SuperviseTargetEntity st : stList) {
				String tRoles = commonMethod.getRolesByDeptId(st.getToSsdwId()+""); //接收角色
				paramsTemp.put("roles", tRoles);
				paramsTemp.put("userId", "1");
				paramsTemp.put("deptId", st.getToSsdwId()+"");
				sysMessageService.insertMessage(paramsTemp);
			}
		}
	}
	

}
